package com.ruifu.proj.controller;

import com.fhzncloud.cloud.common.security.service.CloudUser;
import com.fhzncloud.cloud.common.security.util.SecurityUtils;
import com.ruifu.common.vo.ResultVO;
import com.ruifu.proj.dto.phasetask.PmPhaseTaskDTO;
import com.ruifu.proj.service.PmPhaseTaskService;
import com.ruifu.proj.vo.phasetask.PmPhaseTaskVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author nyr
 * @create 2019/8/7
 */
@RestController
@CrossOrigin
@RequestMapping("/pmPhaseTask")
public class PmPhaseTaskController {

    @Autowired
    private PmPhaseTaskService pmPhaseTaskService;

    /**
     * 用于存储登陆人信息
     */
    private CloudUser cloudUser;

    /**
     * 通过url请求方法之前,调用该方法获取登陆人信息
     */
    @ModelAttribute
    public void before() {
        cloudUser= SecurityUtils.getUser();
    }

    /**
     * 根据项目id查询阶段任务配置列表
     *
     * @param ptId
     * @return
     */
    @GetMapping("/findByPpPtid")
    public List<PmPhaseTaskVO> findByPpPtid(Long ptId) {
        return pmPhaseTaskService.findByPpPtid(ptId);
    }


    /**
     * 保存配置
     *
     * @param phaseTaskDTOList
     * @return
     */
    @PostMapping("/save")
    public ResultVO save(@RequestBody List<PmPhaseTaskDTO> phaseTaskDTOList) {
        try {
            pmPhaseTaskService.save(phaseTaskDTOList, cloudUser);
            return new ResultVO(true, "保存成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultVO(false, "保存失败");
        }
    }
}
